home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / smashing / keithm / Viewport.as < prev    next >
Encoding:
Text File  |  2009-06-09  |  7.6 KB  |  228 lines

  1. class smashing.keithm.Viewport
  2. {
  3.    static var __a_groups;
  4.    static var __o_groups;
  5.    static var __dimensions;
  6.    static var __viewportPath;
  7.    static var __viewportDepth;
  8.    static var __useScrollport;
  9.    static var __instance;
  10.    static var __scrollportDepth;
  11.    static var mc;
  12.    static var scrollmc;
  13.    static var __defaultMCDepth = 100;
  14.    function Viewport(t_path, t_depth, dimensions)
  15.    {
  16.       smashing.keithm.Viewport.__a_groups = [];
  17.       smashing.keithm.Viewport.__o_groups = {};
  18.       smashing.keithm.Viewport.__dimensions = dimensions;
  19.       smashing.keithm.Viewport.__viewportPath = t_path;
  20.       smashing.keithm.Viewport.__viewportDepth = t_depth;
  21.       smashing.keithm.Viewport.__useScrollport = false;
  22.       trace("-- Init Viewport --");
  23.    }
  24.    static function init(t_path, t_depth, dimensions)
  25.    {
  26.       smashing.keithm.Viewport.__instance = new smashing.keithm.Viewport(t_path,t_depth,dimensions);
  27.    }
  28.    static function getInstance()
  29.    {
  30.       return smashing.keithm.Viewport.__instance;
  31.    }
  32.    function setScrollport(t_depth)
  33.    {
  34.       smashing.keithm.Viewport.__useScrollport = true;
  35.       smashing.keithm.Viewport.__scrollportDepth = t_depth;
  36.    }
  37.    function reset()
  38.    {
  39.       var _loc6_ = smashing.keithm.Viewport.__a_groups.length;
  40.       var _loc2_ = undefined;
  41.       var _loc5_ = [];
  42.       var _loc3_ = 0;
  43.       while(_loc5_.length < _loc6_)
  44.       {
  45.          _loc2_ = smashing.keithm.Viewport.__a_groups.length;
  46.          while(true)
  47.          {
  48.             _loc2_;
  49.             if(!_loc2_--)
  50.             {
  51.                break;
  52.             }
  53.             if(smashing.keithm.Viewport.__a_groups[_loc2_].index < smashing.keithm.Viewport.__a_groups[_loc3_].index)
  54.             {
  55.                _loc3_ = _loc2_;
  56.             }
  57.          }
  58.          _loc5_.push(smashing.keithm.Viewport.__a_groups[_loc3_]);
  59.          smashing.keithm.Viewport.__a_groups.splice(_loc3_,1);
  60.       }
  61.       smashing.keithm.Viewport.__a_groups = _loc5_;
  62.       var _loc4_ = smashing.keithm.Viewport.__defaultMCDepth;
  63.       _loc2_ = 0;
  64.       while(_loc2_ < smashing.keithm.Viewport.__a_groups.length)
  65.       {
  66.          _loc4_ = smashing.keithm.Viewport.__a_groups[_loc2_].init(_loc4_);
  67.          _loc4_ = _loc4_ + 1;
  68.          _loc2_ = _loc2_ + 1;
  69.       }
  70.       this.newView();
  71.    }
  72.    function newView()
  73.    {
  74.       var _loc1_ = smashing.keithm.Viewport.__a_groups.length;
  75.       while(true)
  76.       {
  77.          _loc1_;
  78.          if(!_loc1_--)
  79.          {
  80.             break;
  81.          }
  82.          smashing.keithm.Viewport.__a_groups[_loc1_].reset();
  83.       }
  84.       if(smashing.keithm.Viewport.mc != undefined)
  85.       {
  86.          smashing.keithm.Viewport.mc.removeMovieClip();
  87.       }
  88.       smashing.keithm.Viewport.mc = smashing.keithm.Viewport.__viewportPath.createEmptyMovieClip("viewport" + smashing.keithm.Viewport.__viewportDepth,smashing.keithm.Viewport.__viewportDepth);
  89.       if(smashing.keithm.Viewport.__useScrollport)
  90.       {
  91.          if(smashing.keithm.Viewport.scrollmc != undefined)
  92.          {
  93.             smashing.keithm.Viewport.scrollmc.removeMovieClip();
  94.          }
  95.          smashing.keithm.Viewport.scrollmc = smashing.keithm.Viewport.__viewportPath.createEmptyMovieClip("scrollport" + smashing.keithm.Viewport.__scrollportDepth,smashing.keithm.Viewport.__scrollportDepth);
  96.          smashing.keithm.Viewport.scrollmc.scrollRect = new flash.geom.Rectangle(0,0,smashing.keithm.Viewport.__dimensions.SCREEN_WIDTH + 1,smashing.keithm.Viewport.__dimensions.SCREEN_HEIGHT);
  97.       }
  98.    }
  99.    function clearGroup(t_group)
  100.    {
  101.       var _loc2_ = smashing.keithm.Viewport.__o_groups[t_group].mcs;
  102.       while(_loc2_.length > 0)
  103.       {
  104.          this.__eraseAsset(_loc2_[0].mc,t_group);
  105.       }
  106.    }
  107.    function draw(t_data)
  108.    {
  109.       var _loc4_ = undefined;
  110.       if(t_data.element != undefined)
  111.       {
  112.          var _loc3_ = t_data.element;
  113.          if(!_loc3_.isSpawned)
  114.          {
  115.             trace("WARNING: despawned entity " + _loc3_.assetID + " received draw request.");
  116.             return undefined;
  117.          }
  118.          _loc4_ = this.__drawElement(_loc3_);
  119.          if(_loc4_ != undefined)
  120.          {
  121.             _loc3_.onDraw(_loc4_,smashing.keithm.Viewport.getInstance());
  122.          }
  123.          trace("ERROR DRAWING ASSET " + _loc3_.assetID);
  124.          return undefined;
  125.       }
  126.       if(t_data.assetID == "_empty")
  127.       {
  128.          return this.__drawEmpty(t_data.groupName,t_data.depth + t_data.depthInfluence);
  129.       }
  130.       return this.__drawAsset(t_data.assetID,t_data.groupName,t_data.depth + t_data.depthInfluence);
  131.    }
  132.    function erase(t_data)
  133.    {
  134.       if(t_data.element != undefined)
  135.       {
  136.          this.__eraseAsset(t_data.element.mc,t_data.element.getDrawType());
  137.          t_data.element.onErase(smashing.keithm.Viewport.getInstance());
  138.       }
  139.       else
  140.       {
  141.          this.__eraseAsset(t_data.mc,t_data.groupName);
  142.       }
  143.    }
  144.    function createGroup(t_data)
  145.    {
  146.       smashing.keithm.Viewport.__a_groups.push(smashing.keithm.Viewport.__o_groups[t_data.name] = new smashing.keithm.ViewportGroup(t_data));
  147.    }
  148.    function requestGroupDepthSort(t_group)
  149.    {
  150.       smashing.keithm.Viewport.__o_groups[t_group].requestDepthSort();
  151.    }
  152.    function requestDepthChange(t_element)
  153.    {
  154.       smashing.keithm.Viewport.__o_groups[t_element.getDrawType()].requestDepthChange(t_element);
  155.    }
  156.    function __drawElement(t_element)
  157.    {
  158.       var _loc5_ = undefined;
  159.       var _loc2_ = smashing.keithm.Viewport.__o_groups[t_element.getDrawType()];
  160.       var _loc7_ = _loc2_.getDepth(t_element[_loc2_.sortAxis] + t_element.depthInfluence);
  161.       var _loc3_ = smashing.keithm.Viewport.mc;
  162.       if(_loc2_.scrollport)
  163.       {
  164.          _loc3_ = smashing.keithm.Viewport.scrollmc;
  165.       }
  166.       if(t_element.assetID == "_empty")
  167.       {
  168.          var _loc4_ = _loc3_.createEmptyMovieClip(t_element.getDrawType() + _loc7_,_loc7_);
  169.       }
  170.       else
  171.       {
  172.          _loc4_ = _loc3_.attachMovie(t_element.assetID,t_element.assetID + _loc7_,_loc7_);
  173.       }
  174.       _loc2_.mcs.push({mc:_loc4_,depth:_loc7_});
  175.       _loc5_.initScale();
  176.       return _loc4_;
  177.    }
  178.    function __drawAsset(t_asset, t_groupName, t_depth)
  179.    {
  180.       var _loc1_ = smashing.keithm.Viewport.__o_groups[t_groupName];
  181.       var _loc6_ = _loc1_.getDepth(t_depth);
  182.       var _loc3_ = smashing.keithm.Viewport.mc;
  183.       if(_loc1_.scrollport)
  184.       {
  185.          _loc3_ = smashing.keithm.Viewport.scrollmc;
  186.       }
  187.       var _loc2_ = _loc3_.attachMovie(t_asset,t_asset + _loc6_,_loc6_);
  188.       _loc1_.mcs.push({mc:_loc2_,depth:_loc6_});
  189.       return _loc2_;
  190.    }
  191.    function __drawEmpty(t_groupName, t_depth)
  192.    {
  193.       var _loc3_ = smashing.keithm.Viewport.__o_groups[t_groupName];
  194.       var _loc6_ = _loc3_.getDepth(t_depth);
  195.       var _loc2_ = smashing.keithm.Viewport.mc;
  196.       if(_loc3_.scrollport)
  197.       {
  198.          _loc2_ = smashing.keithm.Viewport.scrollmc;
  199.       }
  200.       var _loc1_ = _loc2_.createEmptyMovieClip(t_groupName + _loc6_,_loc6_);
  201.       smashing.keithm.Viewport.__o_groups[t_groupName].mcs.push({mc:_loc1_,depth:_loc6_});
  202.       return _loc1_;
  203.    }
  204.    function __eraseAsset(t_mc, t_groupName)
  205.    {
  206.       var _loc2_ = smashing.keithm.Viewport.__o_groups[t_groupName];
  207.       var _loc1_ = _loc2_.mcs.length;
  208.       while(true)
  209.       {
  210.          _loc1_;
  211.          if(!_loc1_--)
  212.          {
  213.             break;
  214.          }
  215.          if(_loc2_.mcs[_loc1_].mc == t_mc)
  216.          {
  217.             _loc2_.mcs[_loc1_].mc.removeMovieClip();
  218.             _loc2_.mcs.splice(_loc1_,1);
  219.             return undefined;
  220.          }
  221.       }
  222.    }
  223.    function toString()
  224.    {
  225.       return "Viewport exists";
  226.    }
  227. }
  228.